package com.sas.common.converter;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = false)
public class RoomStatusConverter implements AttributeConverter<Integer, String> {

    @Override
    public String convertToDatabaseColumn(Integer attribute) {
        if (attribute == null) return null;
        switch (attribute) {
            case 1: return "AVAILABLE";
            case 2: return "OCCUPIED";
            case 3: return "MAINTENANCE";
            case 4: return "RESERVED";
            default: return "AVAILABLE";
        }
    }

    @Override
    public Integer convertToEntityAttribute(String dbData) {
        if (dbData == null) return null;
        switch (dbData) {
            case "AVAILABLE": return 1;
            case "OCCUPIED": return 2;
            case "MAINTENANCE": return 3;
            case "RESERVED": return 4;
            // 兼容前端传入的 DISABLED，将其视为 RESERVED
            case "DISABLED": return 4;
            default: return 1;
        }
    }
}